﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using HYCodeBase.Algorithm.LRUCache;

namespace HYRevitCode.CurveUtility
{
	public static class CurveCacheUtility
	{
		public static XYZ GetEndPoint_Cache(this Curve inputCurve, int index)
		{
			XYZ xyz = null;
			Dictionary<int, XYZ> dictionary = null;
			if (!CurveCacheUtility.m_useCache.TryGet(inputCurve, out dictionary))
			{
				dictionary = new Dictionary<int, XYZ>();
				CurveCacheUtility.m_useCache.Set(inputCurve, dictionary);
			}
			if (!dictionary.TryGetValue(index, out xyz))
			{
				xyz = inputCurve.GetEndPoint(index);
				dictionary.Add(index, xyz);
			}
			return xyz;
		}

		private static int m_useCapacity = 500;

		private static LRUCacheManger<Curve, Dictionary<int, XYZ>> m_useCache = new LRUCacheManger<Curve, Dictionary<int, XYZ>>(CurveCacheUtility.m_useCapacity);
	}
}
